/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.homesoft.component;

import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.MutableComboBoxModel;

/**
 *
 * @author phucan
 */
public class SuggestedComboBoxModel extends AbstractListModel<Object> implements MutableComboBoxModel<Object> {

    Object selectedItem;
    List list;
//List<ListItem> list;
//    @Override
//    public void setSelectedItem(Object anItem) {
//        selectedItem= anItem;
//    }
//
//    @Override
//    public Object getSelectedItem() {
//        return selectedItem;
//    }

    @Override
    public int getSize() {
        return list.size();
    }

    @Override
    public Object getElementAt(int index) {
        return list.get(index);
    }

    public void setData(List data) {
        if (list == null) {
            list = data;
        } else {
            this.list.clear();
            this.list.addAll(data);
        }
    }

    @Override
    public void addElement(Object item) {
        list.add(item);
        //fireContentsChanged(this, list.size(), list.size());
        //fireIntervalAdded(this, list.size(), list.size());
    }

    @Override
    public void removeElement(Object obj) {
        int i=list.indexOf(obj);
        list.remove(obj);
      //  fireContentsChanged(this, i,i);
        //fireIntervalRemoved(this, i, i);
    }

    @Override
    public void insertElementAt(Object item, int index) {
        list.add(index, item);
    }

    @Override
    public void removeElementAt(int index) {
        list.remove(index);
    }

    @Override
    public void setSelectedItem(Object anItem) {
        this.selectedItem = anItem;
    }

    @Override
    public Object getSelectedItem() {
        return selectedItem;
    }

}
